package licode.unisop.realm.domainx.model;

import licode.unisop.realm.domainx.ability.AccountAbility;
import licode.unisop.realm.domainx.dp.Account;
import licode.unisop.realm.domainx.dp.AccountCategory;
import org.springframework.util.Assert;

/**
 * 登录的账号信息，包括账号名称、账号类别、密码类别、密码等信息
 *
 * @author WR
 */
public class AccountVo {

    private final String userId;

    private final Account account;

    /**
     * 账号类别（mobile/email）
     */
    private final AccountCategory category;

    public AccountVo(String userId, Account account, AccountCategory category) {
        Assert.isTrue(AccountAbility.checkAccount(account, category),
                "账号和类型不匹配");
        this.userId = userId;
        this.account = account;
        this.category = category;
    }

    public String getUserId() {
        return userId;
    }

    public Account getAccount() {
        return account;
    }

    public AccountCategory getCategory() {
        return category;
    }

    public boolean equals(AccountVo other) {
        if (other == this) {
            // 错误
            return false;
        } else {
            return this.account.equals(other.getAccount()) &&
                    this.category.equals(other.getCategory());
        }
    }

    @Override
    public String toString() {
        return "AccountVo{" +
                "account=" + account +
                ", category=" + category +
                '}';
    }
}
